{% extends "base_detail.html" %}

{% load i18n %}
{% load markup %}
{% load comments %}
{% load breadcrumbs %}
{% load menu %}
{% load avatar %}

{% block breadcrumbs %}
    {% add_crumb 'Home' '/' %}
    {% add_crumb 'FAQs' '/faq/' %}
    {% add_crumb object %}
{% endblock %}

{% block objectactions %}
{% if perms.knowledge.add_faq %}
<li class="add"><a title="{% trans 'Add' %}" href="{% url faq_add %}">{% trans 'Add' %}</a></li>
{% endif %}
{% if object.pk in obj_perms.knowledge.change_faq %}
<li class="edit"><a title="{% trans 'Edit' %}" href="{% url faq_edit object.pk %}">{% trans 'Edit' %}</a></li>
{% endif %}
{% if object.pk in obj_perms.knowledge.delete_faq %}
<li class="delete"><a title="{% trans 'Delete' %}" href="{% url faq_delete object.pk %}">{% trans 'Delete' %}</a></li>
{% endif %}
{% if perms.knowledge.view_faq %}
<li class="all"><a title="{% trans 'All' %}" href="{% url faq_list %}">{% trans 'All' %}</a></li>
{% endif %}
{% if perms.knoweldge.view_faq %}
{% if user not in object.stream.followers.all %}
<li class="follow"><a title="{% trans 'Follow' %}" href="{% url stream_follow object.stream request.path %}">{% trans 'Follow' %}</a></li>
{% else %}
<li class="leave"><a title="{% trans 'Leave' %}" href="{% url stream_leave object.stream request.path %}">{% trans 'Leave' %}</a></li>
{% endif %}
{% endif %}
{% endblock %}

{% block objectmenu %}{% menu "faq_menu" %}{% endblock %}

{% block section %}
<div class="details">
    {{ object.question|markdown }}
    <p>
        {% include "elements/categories.html" %}
        {% include "elements/tags.html" %}
    </p>
</div>
<div id="answers">
    <h3>{% trans "Answers" %}</h3>
    {% with answers=object.answer_set.all %}
    {% if answers %}
    <ul>
        {% for answer in answers %}
        <li{% if forloop.counter|divisibleby:"2" %} class="altrow"{% endif %}>
            <div class="meta">
                {% with user_name=answer.author user_link=answer.author.get_absolute_url submit_date=answer.created %}
                {% avatar answer.author %}
                <p>{% blocktrans %}Posted on {{ submit_date }}{% endblocktrans %}{% if answer.author %}{% blocktrans %} by <a href="{{ user_link }}">{{ user_name }}</a>{% endblocktrans %}{% endif %}</p>
                {% endwith %}
                <ul class="actions">
                    {% if perms.answers.can_delete %}
                    <li class="delete"><a title="{% trans 'Delete' %}" href="{% url answer_delete object.id answer.id %}">{% trans "Delete" %}</a></li>
                    {% endif %}
                </ul>
            </div>
            <div class="body">
                {{ answer.answer|markdown }}
            </div>
        </li>
        {% endfor %}
    </ul>
    {% with answer_count=answers.count %}
    <p class="answer-counter">{% blocktrans %}<strong>{{ answer_count }}</strong> answer(s){% endblocktrans %}</p>
    {% endwith %}
    {% else %}
    <p class="disabled">{% trans "No answers." %}</p>
    {% endif %}
    {% endwith %}
    {% if user.is_authenticated %}
    <h3>{% trans "Add answer" %}</h3>
    <form action="." method="post">
        {% csrf_token %}
        {% for field in form %}
        <p>{{ field }}</p>
        {% endfor %}
        <span class="submit"><input type="submit" name="post" value="{% trans 'Post' %}"></span>
    </form>
    {% endif %}
</div>
{% endblock %}
